#include "prompt.h"


void printTitle()
{
	printf(" ********** Welcome to Xinzaibing's E-mail Client ********** \n");
	printf(" **********        Press any Key to Continue        ********** \n");
	getchar();
}

const char* getUserName()
{
	printf(" ** Please Enter your user name (The max name length is 20): ** \n");
	memset((void*)userName, 0, sizeof(userName));	
	fgets(userName, MAX_USER_NAME_LEN, stdin);
	if(strlen(userName)>0)	
	{
		userName[strlen(userName)-1]='\0';
		return base64_encode(userName);	
	}
			
	return NULL;
}

const char* getPassword()
{
	printf(" ** Please Enter your password (The max password length is 20): ** \n");
	memset((void *)password, 0, sizeof(password));
	fgets(password, MAX_PASSWORD_LEN, stdin);
	if(strlen(password)>0)
	{
		password[strlen(password)-1]='\0';
		return base64_encode(password);	
	}
	return NULL;
}

const char* getTargetAddress()
{
	printf(" ** Please Enter the E-mail receiver ... ** \n");
	memset((void *)targetAddress, 0, sizeof(targetAddress));
	memset((void *)originTargetAddress, 0, sizeof(originTargetAddress));
	
	fgets(originTargetAddress, MAX_ADDRESS_LEN, stdin);
	if(strlen(originTargetAddress)>0)
	{
		originTargetAddress[strlen(originTargetAddress)-1]='\0';
		sprintf(targetAddress, "RCPT TO:<%s>\r\n", originTargetAddress);
		return targetAddress;
	}
	else
		return NULL;
}

const char* getSourceAddress()
{
	memset((void *)sourceAddress, 0, sizeof(sourceAddress));
	sprintf(sourceAddress, "MAIL FROM:<%s@qq.com>\r\n", userName);
	printf("Sender: %s\n", sourceAddress);
	return sourceAddress;
}

const char* getData()
{
	printf(" ** Please Enter the Subject... ** \n");
	char subject[50]={0};
	fgets(subject, 50, stdin);
	subject[strlen(subject)-1]='\0';
	printf(" ** Please Enter the text... ** \n");
	memset((void *)text, 0, sizeof(text));

	char tmpText[1024*1024]={0};
	fgets(tmpText, MAX_TEXT_LEN, stdin);
	tmpText[strlen(tmpText)-1]='\0';
	sprintf(text, "from:%s@qq.com\nto:%s\nsubject:%s\n\n%s\r\n.\r\n", userName, originTargetAddress, subject, tmpText);

	printf(" text :\n%s\n", text);
	return text;
}


